/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TestCloud;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.security.auth.login.LoginException;
import net.elbandi.pve2api.Pve2Api;
import net.elbandi.pve2api.RestClient;
import net.elbandi.pve2api.RestClientSimple;
import net.elbandi.pve2api.data.AplInfo;
import net.elbandi.pve2api.data.Network;
import net.elbandi.pve2api.data.VmOpenvz;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author romain
 */
public class MainTestCloud {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws UnsupportedEncodingException, IOException, LoginException, JSONException, URISyntaxException {
        // TODO code application logic here
     
        Pve2Api proxmox = new Pve2Api("37.59.44.215", "root","pam", "VpX4HBkR");
        //proxmox.login();


        

        List<String> node;
        node = proxmox.getNodeList();
        System.out.println("size de la Node List: "+node.size());
        System.out.println("voici la Node List: "+node);

        for(int i=0;i<node.size();i++){
            System.out.println("node: "+node.get(i));
            //List<AplInfo> nodeappliance;
            List<VmOpenvz> nodeOpenvz;
            nodeOpenvz = proxmox.getOpenvzCTs(node.get(i));
            //nodeappliance = proxmox.getNodeAppliances(node.get(i));
            System.out.println("size de la liste de containeur: "+nodeOpenvz.size());
            for(int j=0;j<nodeOpenvz.size();j++){
                System.out.println("containeur: "+nodeOpenvz.get(j).getName());
                System.out.println("VMID: "+nodeOpenvz.get(j).getVmid());
                System.out.println("Netif: "+nodeOpenvz.get(j).getNetin()+"  "+nodeOpenvz.get(j).getNetout());
            }

            
        }

        //    VmOpenvz contain1 = new VmOpenvz("edithTelecom", "local:vztmpl/debian-6.0-standard_6.0-6_amd64.tar.gz","192.168.1.50",110);
        //    proxmox.createOpenvz(contain1);

        proxmox.deleteOpenvz("ks399918", 150);
        //System.out.println(proxmox.pve_action("/nodes/ks399918/network", RestClient.RequestMethod.GET, null).toString());






        //List<AplInfo> result;

        /*HttpHost proxy = new HttpHost("wwwcache.insa-toulouse.fr", 3128, "http");
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

            HttpHost target = new HttpHost("issues.apache.org", 443, "https");
            HttpGet req = new HttpGet("/");

            System.out.println("executing request to " + target + " via " + proxy);
            HttpResponse rsp = httpclient.execute(target, req);
            HttpEntity entity = rsp.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(rsp.getStatusLine());
            Header[] headers = rsp.getAllHeaders();
            for (int i = 0; i<headers.length; i++) {
                System.out.println(headers[i]);
            }
            System.out.println("----------------------------------------");

            if (entity != null) {
                System.out.println(EntityUtils.toString(entity));
            }

        } finally {
            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpclient.getConnectionManager().shutdown();
        }*/
    }

}
